package com.geewaza.sonarqube.webapi.api.qualityprofiles;

import com.geewaza.sonarqube.webapi.api.AbstractService;
import com.geewaza.sonarqube.webapi.client.http.BaseHttpClient;

import java.io.IOException;

/**
 * Restore a quality profile using an XML file. The restored profile name is taken from the backup file, so if a profile with the same name and language already exists, it will be overwritten.
 * Requires to be logged in and the 'Administer Quality Profiles' permission.
 *
 * @author : wangheng
 * @date : 2022-05-05 14:50
 **/
public class RestoreQualityProfileService extends AbstractService<RestoreQualityProfileService, Boolean> {
    public RestoreQualityProfileService(BaseHttpClient httpClient) {
        super(httpClient);
    }

    @Override
    protected String[] requiredParam() {
        return new String[] {"backup"};
    }

    @Override
    protected Boolean doExecute() throws IOException {
        doPost("api/qualityprofiles/restore");
        return true;
    }

    /**
     * A profile backup file in XML format, as generated by api/qualityprofiles/backup or the former api/profiles/backup.
     *
     * @param backup A profile backup file in XML format, as generated by api/qualityprofiles/backup or the former api/profiles/backup.
     * @return
     */
    public RestoreQualityProfileService backup(String backup) {
        return put("backup", backup);
    }

}
